package com.zte.warehouse.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zte.warehouse.dao.IWarehouseDao;
import com.zte.warehouse.model.SingleWarehouse;
import com.zte.warehouse.model.getUserMSG;
import com.zte.warehouse.model.Warehouse;
import com.zte.warehouse.model.WarehouseCondition;
import com.zte.warehouse.service.IWarehouseService;
import com.zte.util.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class WarehouseService implements IWarehouseService {

    @Autowired
    private IWarehouseDao WarehouseDao;

    //    分页查询
    @Override
    public PageModel<Warehouse> queryWarehousePageByCondition(PageModel<Warehouse> pageModel, WarehouseCondition conn) {
        int pageNum = pageModel.getPageNum() <= 0 ? 1 : pageModel.getPageNum();
        int pageSize = pageModel.getPageSize() <= 0 ? 3 : pageModel.getPageSize();

        PageHelper.startPage(pageNum, pageSize);
        List<Warehouse> warehouses = WarehouseDao.queryWarehouseListByCondition(conn);
        PageInfo<Warehouse> info = new PageInfo<Warehouse>(warehouses);

        pageModel.setPageNum(info.getPageNum());
        pageModel.setPageSize(info.getPageSize());
        pageModel.setTotalPage(info.getPages());
        pageModel.setTotalCount((int) info.getTotal());
        pageModel.setData(new ArrayList<Warehouse>(info.getList()));
        return pageModel;
    }


    //加载仓库列表
    @Override
    public List<SingleWarehouse> queryWarehouseList() {
        return WarehouseDao.queryWarehouseList();
    }


    //    查单个
    @Override
    public Warehouse queryUserByCondition(WarehouseCondition conn) {
        return WarehouseDao.queryWarehouseByCondition(conn);
    }

    //加载财务部仓管
    @Override
    public List<getUserMSG> getWarehouseUsre() {
        return WarehouseDao.getWarehouseUsre();
    }

    //    添加仓库
    @Override
    public int addWarehouse(SingleWarehouse warehouse) {
        return WarehouseDao.addWarehouse(warehouse);
    }

    //    更新仓库
    @Override
    public int updateWarehouse(SingleWarehouse singleWarehouse) {
        return WarehouseDao.updateWarehouse(singleWarehouse);
    }

    //    删除仓库
    @Override
    public int deleteWarehouseById(String id) {
        return WarehouseDao.deleteWarehouseById(id);
    }
}
